//
//  SHBlockViewController.m
//  Block传值~demo
//
//  Created by 石虎 on 2017/9/22.
//  Copyright © 2017年 石虎. All rights reserved.
//

#import "SHBlockViewController.h"
#import "ViewController.h"

@interface SHBlockViewController ()

@property (weak, nonatomic) IBOutlet UITextField *startValueField;
- (IBAction)startValueClick:(UIButton *)sender;

@end

@implementation SHBlockViewController

//返回到上级界面
- (IBAction)startValueClick:(UIButton *)sender {
    
    [self dismissViewControllerAnimated:YES completion:nil];
}

// block实际执行的内容
-(void)showTheResultToFirst:(SHBlockViewBlock)block {
    self.passValue = block;
}

// 在即将消失 view时，将 block 方法的参数设置为文本框的内容
-(void)viewWillDisappear:(BOOL)animated {
    
    if (self.passValue != nil) {
        self.passValue(self.startValueField.text);
    }
}
//退出键盘
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.view endEditing:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
}

@end
